﻿@using Backend.JYD.Model
<style type="text/css">
 .dtree {
	font-size: 11px; color: #666; font-family: verdana, geneva, arial, helvetica, sans-serif; white-space: nowrap
}
.dtree img {
	border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;
}
.dtree a {
	color: #333; text-decoration: none
}
.dtree a.node {
	padding-right: 2px; padding-left: 2px; padding-bottom: 1px; padding-top: 1px; white-space: nowrap
}
.dtree a.nodesel {
	padding-right: 2px; padding-left: 2px; padding-bottom: 1px; padding-top: 1px; white-space: nowrap
}
.dtree a.node:hover {
	color: #333; text-decoration: underline
}
.dtree a.nodesel:hover {
	color: #333; text-decoration: underline
}
.dtree a.nodesel {
	background-color: #c0d2ec
}
.selectnode
{
    color:red;
}
.dtree .clip {
	overflow: hidden
}

</style>
@{
    var nodes = this.ViewBag.TreeNodes as List<TreeNodeInfo>;

    if(nodes!= null && nodes.Count>0) {
    
        //判断是否存在一个节点是展开的，如果又，将其父节点设置为展开
        List<TreeNodeInfo> exps = nodes.FindAll(p=>p.Expanded);
        if(exps != null && exps.Count>0)
        {
            foreach(var exp in exps)
            {
                var parent = nodes.Find(p=>exp.ParentId.HasValue && exp.ParentId.Value == p.Id);
                while(parent != null)
                {
                    parent.Expanded = true;
                    parent = nodes.Find(p=>parent.ParentId.HasValue && parent.ParentId.Value == p.Id);
                }
            }
        
            List<TreeNodeInfo> tops = nodes.FindAll(r => r.ParentId == null || r.ParentId.Value<=0);
           <div style="margin-left:10px;">
            @for (int k = 0; k < tops.Count; k++)
            {
                var top = tops[k];
                if (null != top)
                {
            <div  style='font-size: 11px; color: #666; font-family: verdana, geneva, arial, helvetica, sans-serif; white-space: nowrap;' >
                <div>
                    <a style="color: #333; text-decoration: none;font-size: 11px;"  href="javascript:ndclk(@top.Id)">
                        <img id="@("igroupTree"+top.Id)" alt="" src="/skin/tree/@(top.Expanded ? "folder_group_open" : "folder_group_close").gif"  style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
                    </a>
                    @top.Name
                </div>
                <div   id="@("dgroupTree"+top.Id)"  style='overflow: hidden;display: block;font-size: 11px;' >
                    @{
                        List<TreeNodeInfo> children = nodes.FindAll(r => r.ParentId == top.Id);
                        if (null != children && children.Count > 0)
                        {
                            
                            //foreach (var child in children)
                            for (int i = 0; i < children.Count; i++)
                            {
                                //var cbefore = (k == tops.Count - 1) ? "wite" : "line";
                                //var before = new List<string>();
                                //if (!string.IsNullOrWhiteSpace(cbefore))
                                //{
                                //    before.Add(cbefore);
                                //}
                                var child = children[i];
                                var data = new ViewDataDictionary();
                                data.Add("Index", i);
                                data.Add("Max", children.Count);
                                data.Add("LastIndex", k);
                                data.Add("LastMax", tops.Count);
                                data.Add("Nodes", nodes);
                                Html.RenderPartial("TreeChildNode", child, data);
                            }
                        }
                    }
                </div>
            </div>
                }
            }
            </div>
        }
    }
}

<script type="text/javascript">
var currentIndex=0;
var currentcloseImage="";
function ndclk(index,openImage,closeImage) {
    if (document.getElementById('dgroupTree' + index) != null) {
        if (document.getElementById('dgroupTree' + index).style.display == 'none') {
            document.getElementById('dgroupTree' + index).style.display = 'block';
            if (document.getElementById('igroupTree' + index) != null) {
                document.getElementById('igroupTree' + index).src ="/skin/tree/folder_group_open.gif";
            }
            if (document.getElementById('jgroupTree' + index) != null) {
                document.getElementById('jgroupTree' + index).src = document.getElementById('jgroupTree' + index).src.replace("plus", "minus");
            }
        } else {
            document.getElementById('dgroupTree' + index).style.display = 'none';
            if (document.getElementById('igroupTree' + index) != null) {
                document.getElementById('igroupTree' + index).src = "/skin/tree/folder_group_close.gif";
            }
            if (document.getElementById('jgroupTree' + index) != null) {
                document.getElementById('jgroupTree' + index).src = document.getElementById('jgroupTree' + index).src.replace("minus", "plus");
            }
        }
    }
    }
function selectNode(index,openImage,closeImage) {
    if (document.getElementById('sgroupTree' + currentIndex) != null) {
        document.getElementById('sgroupTree' + currentIndex).style.color = "#333";
    }
    if (document.getElementById('sgroupTree' + index) != null) {
        document.getElementById('sgroupTree' + index).style.color = "Red";
    }
    if (document.getElementById('igroupTree' + currentIndex) != null) {
        if(currentcloseImage!="") {
            document.getElementById('igroupTree' + currentIndex).src = "/skin/tree/folder_group_close.gif";
        }
    }
    if (document.getElementById('igroupTree' + index) != null) {
        document.getElementById('igroupTree' + index).src = "/skin/tree/folder_group_close.gif";
    }
    currentIndex= index;
    currentcloseImage = "/skin/tree/folder_group_close.gif";
}

function o(index) {
    if (document.getElementById('dgroupTree' + index) != null) {
        if (document.getElementById('dgroupTree' + index).style.display == 'none') {
            document.getElementById('dgroupTree' + index).style.display = 'block';

        } else {
            document.getElementById('dgroupTree' + index).style.display = 'none';
        }
        if (document.getElementById('igroupTree' + currentIndex) != null) {

        }
    }
}
</script>
            
